package com.qiaofang.applet.service.member.service;

import com.qiaofang.applet.common.base.BaseService;
import com.qiaofang.applet.service.member.domain.Employee;
import com.qiaofang.applet.service.member.service.dto.*;
import com.qiaofang.applet.service.property.domain.FirsthandEstate;
import com.qiaofang.applet.service.property.domain.Property;
import com.qiaofang.applet.service.property.service.dto.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.support.PageableExecutionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author daiyuxiang
 */
public interface EmployeeService extends BaseService<Employee, String> {

    Page<Employee> findAllByParams(EmployeeQueryDto query, Pageable pageable);

    Page<EmployeeListDto> convertDomainToListDto(Page<Employee> employeePage, String corporationCode);

    /**
     * 因分页总数从第一次查询的page中取值，传入第一次总数
     * @param employeePage
     * @param total
     * @return
     */
    Page<EmployeeListDto> convertDomainToListDto(Page<Employee> employeePage, long total);

    Employee findByEmployeeUniqueUuid(String employeeUniqueUuid);

    /**
     * 保存经纪人信息
     *
     * @param employee
     */
    void saveEmployee(Employee employee);

    List<Employee> findAllByEmployeeUuidInAndCompanyUuid(List<String> uuidList, String companyUuid);

    /**
     * 根据集团编号和员工uuid查询员工信息
     *
     * @param corporationCode
     * @param uuidList
     * @return
     */
    List<Employee> findAllByEmployeeUuidIn(String corporationCode, List<String> uuidList);

    List<EmployeeListDto> getEmployeeListDtoByPropety(Property property);

    List<EmployeeListDto> getEmployeeListDtoByFirsthandEstate(FirsthandEstate firsthandEstate);

    EmployeeListDto domainToListDto(Employee employee);

    EmployeeDetailDto domainToDetailDto(Employee employee, Map<String, String> cityMap);

    List<Employee> findByCorporationCodeAndMobilePhone(String corporationCode, String phone);

    ShowEmpUuidDto getEmployeeUuidDtoByProperty(String propertyUniqueUuid);

    PropertyEmpDto getEmployeeDtoByProperty(String propertyUniqueUuid);

    ShowEmpUuidDto getV20EmployeeUuidDtoByProperty(String propertyUniqueUuid);

    PropertyEmpDto getV20EmployeeDtoByProperty(String propertyUniqueUuid);

    ShowEmpUuidDto getEmployeeUuidDtoByFirsthand(String estateUniqueUuid);

    PropertyEmpDto getEmployeeDtoByFirsthand(String estateUniqueUuid);

    default Page<EmployeeListDto> convertDomainToListDto(Page<Employee> employeePage) {
        List<EmployeeListDto> content = new ArrayList<>();

        if (employeePage.getTotalElements() > 0) {
            content = employeePage.getContent().parallelStream().map(this::domainToListDto).collect(Collectors.toList());
        }

        return PageableExecutionUtils.getPage(content, employeePage.getPageable(), () -> employeePage.getTotalElements());
    }

    /**
     * 经纪人的访客列表
     * @param employeeUniqueUuid
     * @return
     */
    List<VisitorRecordsListDto> listVisitorRecords(String employeeUniqueUuid);

    /**
     * 新访客列表
     * @param employeeUniqueUuid
     * @return
     */
    List<VisitorRecordsSimpleDto> newVisitorRecords(String employeeUniqueUuid);

    Page<EmployeeListDto> getEmployeeList(EmployeeListQueryDto queryDto, Pageable pageable);

    List<EmployeeListDto> domainToListDtoList(List<Employee> employeeList);

    Map<String, EmpFansAndExchangeDto> getFansAndExchangeCount();

    /**
     * 获取公司所有经纪人基础信息（报表）
     * @param corporationCode
     * @param companyUuid
     * @return
     */
    List<ReportBaseDto> getEmpBaseInfo(String corporationCode, String companyUuid);
}
